package sort;
//选择排序
public class Selection {
    public static void sort(Comparable[] a ){
        for (int i = 0; i <a.length-1 ; i++){
            int cur = i;
            for (int j = i; j <a.length-1;j++){
               if (grate(a[cur],a[j+1])){
                    cur = j+1;
                }
            }
            exch(a,i,cur);
        }
    }
    //判断两个数值的大小
    private static Boolean grate(Comparable x, Comparable y){
        return x.compareTo(y) > 0;
    }
    //交换两个元素的位置
    private static void exch(Comparable[] a, int i ,int j){
        Comparable tem = a[i];
        a[i] = a[j];
        a[j] = tem;
    }
}
